package leetcode.leetcode100;

import java.util.HashMap;

public class twoSum {
    public static void main(String[] args) {
        int[] nums = {3,3};
        int[] ans = process(nums,6);
        for (int a:ans) {
            System.out.println(a);
        }
    }
    public static int[] process(int[] nums,int target){
        int[] ans = new int[2];//返回数组
        HashMap<Integer, Integer> hashMap = new HashMap<>();//key:数组元素，value:元素下标
        for (int i = 0; i < nums.length; i++) {
            hashMap.put(nums[i],i);
        }
        for (int i = 0; i < nums.length; i++) {
            int cur = target - nums[i];
            if (hashMap.containsKey(cur) && hashMap.get(cur)!=i){
                ans[0] = i;
                ans[1] = hashMap.get(cur);
            }
        }
        return ans;
    }

}
